﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using AspNetCs.Common;

public partial class AjaxXml_UpdateAccessCount : Admin_BasePage
{
    private int ChannelType = 0;
    private int AccessCount = 0;
    private int Id = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        IsExit();
        if(!IsPostBack)
        {
            GetParas();
            bool bo=UpdateAccessCount();
            if (bo)
            {
                Response.Write("OK");       
            }
            else
            {
                Response.Write("Error"); 
            }
            Response.End();
        }

    }

    /// <summary>
    /// 获得参数
    /// </summary>
    private void GetParas()
    {
        if (string.IsNullOrEmpty(Request["ChannelType"]) || string.IsNullOrEmpty(Request["Id"]) || string.IsNullOrEmpty(Request["AccessCount"]))
        {
            //Response.Redirect("../Master/Admin_login.Aspx");
            Response.Write("Error");
            Response.End();

        }
        else
        {
            ChannelType = StringHelper.isNumber_int(Request.QueryString["ChannelType"]);
            AccessCount = StringHelper.isNumber_int(Request.QueryString["AccessCount"]);
            Id = StringHelper.isNumber_int(Request.QueryString["Id"]);
        }
        
    }


    private bool UpdateAccessCount()
    {
        bool bo = false;
        switch (ChannelType)
        {
            //纪念馆
            case 0:
                bo=EditMemorialAccessCount();
                break;
            //公墓
            case 1:
                bo = EditNetMuAccessCount();
                break;
            //陵园
            case 2:
                bo = EditCemeteryAccessCount();
                break;
            //宗祠
            case 3:
                bo = EditAncestralHallAccessCount();
                break;
            //海内外寻亲
            case 4:
                bo = EditFindFamilyAccessCount();
                break;
            //宠物乐园
            case 5:
                bo = EditHappyPetAccessCount();
                break;
            default:
                Response.Write("Error");
                Response.End();
                break;
        }
        return bo;
    }

    /// <summary>
    /// 公墓访问量修改
    /// </summary>
    /// <returns></returns>
    private bool EditNetMuAccessCount()
    {
        int  re = 0;
        string cmdText = "update NetMu set hot={0} where Id={1}";
        cmdText = string.Format(cmdText, AccessCount, Id);
        dbclass db = new dbclass();
        re = db.ExecuteReRow_SQL(cmdText);
        return re>0?true:false;
    }

    /// <summary>
    /// 纪念馆访问量修改
    /// </summary>
    /// <returns></returns>
    private bool EditMemorialAccessCount()
    {
        int re = 0;
        string cmdText = "update memorial set hot={0} where ID={1}";
        cmdText = string.Format(cmdText, AccessCount, Id);
        dbclass db = new dbclass();
        re = db.ExecuteReRow_SQL(cmdText);
        return re > 0 ? true : false;
    }

    /// <summary>
    /// 宗祠访问量修改
    /// </summary>
    /// <returns></returns>
    private bool EditAncestralHallAccessCount()
    {
        int re = 0;
        string cmdText = "update AncestralHall set AcceeCount={0} where Id={1}";
        cmdText = string.Format(cmdText, AccessCount, Id);
        dbclass db = new dbclass();
        re = db.ExecuteReRow_SQL(cmdText);
        return re > 0 ? true : false;
    }

    /// <summary>
    /// 陵园访问量修改
    /// </summary>
    /// <returns></returns>
    private bool EditCemeteryAccessCount()
    {
        int re = 0;
        string cmdText = "update Cemetery set hot={0} where Id={1}";
        cmdText = string.Format(cmdText, AccessCount, Id);
        dbclass db = new dbclass();
        re = db.ExecuteReRow_SQL(cmdText);
        return re > 0 ? true : false;
    }

    /// <summary>
    /// 海内外访问量修改
    /// </summary>
    /// <returns></returns>
    private bool EditFindFamilyAccessCount()
    {
        int re = 0;
        string cmdText = "update FindFamily set AcceeCount={0} where Id={1}";
        cmdText = string.Format(cmdText, AccessCount, Id);
        dbclass db = new dbclass();
        re = db.ExecuteReRow_SQL(cmdText);
        return re > 0 ? true : false;
    }

    /// <summary>
    /// 宠物乐园访问量修改
    /// </summary>
    /// <returns></returns>
    private bool EditHappyPetAccessCount()
    {
        int re = 0;
        string cmdText = "update HappyPet set AcceeCount={0} where Id={1}";
        cmdText = string.Format(cmdText, AccessCount, Id);
        dbclass db = new dbclass();
        re = db.ExecuteReRow_SQL(cmdText);
        return re > 0 ? true : false;
    }
}
